# encoding  :  utf-8 _*_
# @author   :  朱清闯
# @software :  PyCharm
# time      :  2022/3/22 15:11

from utils import GenarateRandCode
from apis.models import Code
import datetime


def generate_rand_code_and_save2database(phone,code_len=4,expiration_time=5):
    rand_code = GenarateRandCode.genarate_Rand_Code(2,4)
    code = Code()
    code.phone = phone
    # 生成随机数验证码
    code.code = str(rand_code)
    # 设定验证码的过期时间为5分钟以后
    code.end_time = datetime.datetime.now() + datetime.timedelta(minutes=expiration_time)
    code.save()
    return rand_code
